package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.item.entity.SpecParam;
import com.leyou.item.mapper.SpecParamMapper;
import com.leyou.item.service.SpecParamService;
import com.leyou.pojo.dto.ParamDTO;
import org.springframework.stereotype.Service;

import java.beans.Transient;
import java.util.List;


@Service
public class SpecParamServiceImpl extends ServiceImpl<SpecParamMapper,SpecParam> implements SpecParamService {

    //新增/修改
    @Override
    @Transient
    public void addOrUpdateSpecParam(ParamDTO paramDTO) {
        SpecParam specParam = paramDTO.toEntity(SpecParam.class);
        this.saveOrUpdate(specParam);
    }

    //根据条件查询规格参数集合
    @Override
    public List<ParamDTO> findParamsByIdOrSearching(Long categoryId, Long groupId, Boolean searching) {
        List<SpecParam> specParams = query()
                .eq(null!=categoryId,"category_id", categoryId)
                .eq(null!=groupId,"group_id", groupId)
                .eq(null!=searching,"searching", searching)
                .list();
        return ParamDTO.convertEntityList(specParams);
    }
}
